package com.thread.thread.ThreadPool线程池;

import java.util.Arrays;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.IntStream;

public class FixedThreadPoolTest {
	//FixedThreadPool创建固定大小的线程池，如果有超过限制数量的线程进入则会等待其他线程释放
	public static ExecutorService executorService=Executors.newFixedThreadPool(5);
	public static void main(String[] args) {
		Thread[] threads=new Thread[7];
		IntStream.range(0,threads.length).forEach(i->{
			threads[i]=new Thread(()-> System.out.println("使用线程"+Thread.currentThread().getName()));

		});

		Arrays.asList(threads).forEach(thread -> executorService.submit(thread));
	}

}
